<?php

namespace app\admin\model\xyvenue;

use think\Model;


class Venue extends Model
{

    

    

    // 表名
    protected $name = 'xyvenue_venue';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'duration_text',
        'status_text'
    ];
    

    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
        });
    }

    public function getAreaAttr($value, $data)
    {
        return json_decode($value, true);
    }

    public function getTimepriceAttr($value, $data)
    {
        return json_decode($value, true);
    }

    public function getHolidaypriceAttr($value, $data)
    {
        return json_decode($value, true);
    }
    
    public function getDurationList()
    {
        return ['30' => __('Duration 30'), '45' => __('Duration 45'), '60' => __('Duration 60'), '90' => __('Duration 90')];
    }

    public function getStatusList()
    {
        return ['normal' => __('Status normal'), 'hidden' => __('Status hidden')];
    }

    public function getIsholidaypriceList()
    {
        return [0 => __('Isholidayprice 0'), 1 => __('Isholidayprice 1')];
    }


    public function getDurationTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['duration']) ? $data['duration'] : '');
        $list = $this->getDurationList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function store()
    {
        return $this->belongsTo('\app\admin\model\xyvenue\store\Store', 'store_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

}
